#include "StdAfx.h"
#include "SceneNodeMotionState.hpp"
#include "..\engine\UnitEntity.hpp"

namespace he
{
	UnitEntity::UnitEntity(UnitPtr_t const &pUnit, Ogre::Entity *pEntity, Ogre::SceneNode *pSceneNode)
		: m_pUnit(pUnit), m_pEntity(pEntity), m_pSceneNode(pSceneNode),
		m_pMotionState(new SceneNodeMotionState(*m_pSceneNode, btTransform(btQuaternion::getIdentity(),
			btVector3(m_pSceneNode->getPosition().x, m_pSceneNode->getPosition().y, m_pSceneNode->getPosition().z))))
	{
		Ogre::Vector3 const bound_box = get_bounding_box();
		m_pCollisionShape.reset(new btBoxShape(btVector3(bound_box.x, bound_box.y, bound_box.z)));
		// Create rigid body
		btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI_tank(1, m_pMotionState.get(), m_pCollisionShape.get(), btVector3(0,0,0));
		m_pRigidBody.reset(new btRigidBody(groundRigidBodyCI_tank));
	}

	Ogre::Entity const &UnitEntity::get_entity() const
	{
		return *m_pEntity;
	}

	Ogre::Vector3 const UnitEntity::get_bounding_box() const
	{
		return get_entity().getMesh()->getBounds().getHalfSize();
	}
} /*he*/
